﻿@using System.Globalization

<FluentGrid>
    <FluentGridItem>
        <FluentAutocomplete TOption="CultureInfo"
                            AutoComplete="off"
                            Label="Select Culture"
                            Width="250px"
                            OnOptionsSearch="OnSearch"
                            Placeholder="Select countries"
                            MaximumOptionsSearch="int.MaxValue"
                            MaximumSelectedOptions="1"
                            Virtualize="true"
                            OptionText="@(item => $"{item.DisplayName} - {item.Name}")"
                            @bind-SelectedOptions="@_selectedCultures" />

        <FluentCalendar Culture="SelectedCulture" @bind-Value="@_selectedValue">
        </FluentCalendar>
        <p>Selected date @(_selectedValue?.ToString("yyyy-MM-dd"))</p>
    </FluentGridItem>
    <FluentGridItem>
        <FluentCalendar @bind-Value="@_selectedValue" Style="margin-top: 56px"  />
    </FluentGridItem>
</FluentGrid>

@code
{
    private DateTime? _selectedValue = null;
    private IEnumerable<CultureInfo> _selectedCultures = [new CultureInfo("fa-IR")];
    private CultureInfo[] Cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
    private CultureInfo SelectedCulture => _selectedCultures.FirstOrDefault() ?? CultureInfo.CurrentCulture;

    private void OnSearch(OptionsSearchEventArgs<CultureInfo> e)
    {
        e.Items = Cultures.Where(culture =>
            culture.Name.Contains(e.Text, StringComparison.OrdinalIgnoreCase) ||
            culture.DisplayName.Contains(e.Text, StringComparison.OrdinalIgnoreCase));
    }
}
